package com.sh4.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.sh4.dao.MenuDao;
import com.sh4.entity.Menu;


@Repository
public class MenuDaoImpl extends BaseDaoImpl<Menu> implements MenuDao {

	@Override
	public List<Menu> getAllMenu(String parentId) {

		String hql = "from Menu where parentId is null";

		return this.getList(hql);
	}
	
	@Override
	public List<Menu> getChildMenu(String parentId) {

		String hql = "from Menu where parentId = ? order by creatTime";

		return this.getList(hql,parentId);
	}

	@Override
	public Menu getMenuById(String id , String permissionId) {

		String hql = "from Menu where id = ?";
		
		return (Menu) this.getUniqueResult(hql, id);
	}

	@Override
	public void save(Menu m) {
		
		Session s = this.sessionFactory.getCurrentSession();
		
		
		s.saveOrUpdate(m);
		
		
	}

}
